<?php

namespace lib\Oss;

use OSS\Core\OssException;
use OSS\OssClient;

class AliOss
{
    /**
     * 根据Config配置，得到一个OssClient实例
     * @return OssClient 一个OssClient实例
     */
    public static function getOssClient()
    {
        try {
            $ossClient = new OssClient(getenv('OSS_ACCESSKEYID'), getenv('OSS_ACCESSKEYSECRET'), getenv('OSS_ENDPOINT'), false);
        } catch (OssException $e) {
            printf(__FUNCTION__ . "creating OssClient instance: FAILED\n");
            printf($e->getMessage() . "\n");
            return null;
        }

        return $ossClient;
    }

    public static function getBucketName()
    {
        return getenv('OSS_BUCKETNAME');
    }
}